<?php include_once __DIR__.'/left.html';?>
<div class="layui-body">
  <!-- 内容主体区域 -->
  <div class="layui-card">
      <div class="layui-card-body">
          <div class="layui-row layui-form" id="form">
              <div class="layui-col-lg3">
                    <div class="layui-col-lg4">
                        <input type="text" id="min_time" name="min_time" placeholder="最小时间" class="layui-input">
                    </div>
                    <div class="layui-col-lg4">
                            <input type="text" id="max_time" name="max_time" placeholder="最大时间" class="layui-input">
                    </div>
                    <div class="layui-col-lg4">
                        <select lay-filter="com_quicktime">
                            <option value="0">快捷时间</option>
                            <option value="1">最近1天</option>
                            <option value="2">最近2天</option>
                            <option value="3">最近3天</option>
                            <option value="4">最近4天</option>
                            <option value="5">最近5天</option>
                            <option value="6">最近6天</option>
                            <option value="7">最近7天</option>
                            <option value="8">最近8天</option>
                            <option value="9">最近9天</option>
                            <option value="10">最近10天</option>
                            <option value="20">最近20天</option>
                            <option value="30">最近30天</option>
                            <option value="60">最近60天</option>
                            <option value="90">最近90天</option>
                            <option value="365">最近365天</option>
                        </select>
                    </div>
                </div>
              <div class="layui-col-lg2">
                  <input type="text" name="keyword" placeholder="请输入关键词" autocomplete="off" class="layui-input">
              </div>

              <div class="layui-col-lg2">
                    <select name="xcdy_id">
                        <option value="">选择单页</option>
                        <?php foreach($lists as $k => $v):?>
                            <option value="<?=$v['id']?>"><?=$v['title']?></option>
                        <?php endforeach;?>
                    </select>
                </div>
              <div class="layui-col-lg1">
                  <button class="layui-btn layui-btn-normal" onclick="search()">搜索</button>
              </div>
          </div>
          <div class="layui-row">
              <table class="layui-hide" lay-filter="table" id="table"></table>
          </div>
      </div>
  </div>
</div>
<script type="text/html" id="barDemo">
  <!-- <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a> -->
  <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
  <!-- <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="see">查看</a> -->
</script>
<script>
layui.use(['table', 'form'], function() {
    var form = layui.form;
    var table = layui.table;
    var $ = layui.$;
    form.render('select');
    search = function() {
        var url = "<?=url('admin/mlists')?>";
        var data = $("#form").find("[name]");
        var where = {};
        data.each(function(i, e) {
            where[$(e).attr('name')] = $(e).val();
        });
        table.render({
            elem: '#table',
            url: url,
            where: where,
            method: 'post',
            //cellMinWidth: 180,
            page: true,
            cols: [
                [
                    { field: 'id', title: 'ID', width: 80, sort: true, title: 'ID' },
                    { field: 'name', title: '姓名' },
                    { field: 'phone', title: '电话' },
                    { field: 'other', title: '其他联系方式' },
                    { field: 'content', title: '留言内容' },
                    { field: 'create_time_name', title: '留言时间' },
                    {field:'action', title: '操作',width:178, align:'right', toolbar: '#barDemo',fixed:"right",}
                ]
            ]
        });
    };
    search();
    //监听工具条
    table.on('tool(table)', function(obj){
      var data = obj.data;
      if(obj.event === 'edit'){
        layer.open({
            title:'编辑',
            type:2,
            area: ['90%', '90%'],
            content:'<?=url('admin/edit')?>?id='+data.id
        });
      } else if(obj.event === 'see'){
        layer.open({
            title:'微信扫码查看',
            type:2,
            area: ['40%', '40%'],
            content:'<?=url('admin/detail')?>?id='+data.id
        });
      } else if(obj.event === 'del'){
        layer.confirm('确认要删除吗?', function(index){
          $.ajax({
              url:'<?=url('admin/mdel')?>?id='+data.id,
              method:"post",
              dataType:"json",
              data:{id:data.id},
              success:function(res){
                  my.action(res);
                  layer.close(index);
              }
          });
        });
      }
    });
    //监听编辑框
    table.on('edit(table)', function(obj) {
        var data = {};
        data['table'] = 'xcdy';
        data['id'] = obj.data.id;
        data['field'] = obj.field;
        data['value'] = obj.value;
        $.ajax({
            url: '<?=url('bbs/com/edit')?>',
            method: 'post',
            dataType: 'json',
            data: data,
            success: function(res) {
                my.action(res);
            }
        });
    });
});
</script>
